#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int N = 110;
string s[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}
	int m;
	cin >> m;
	while (m--) {
		int x;
		cin >> x;
		if (s[x] != "?") {
			cout << s[x] << endl;
			continue;
		}
		int l = 0, r = 0;
		for (int i = x + 1; i <= n; i++) {
			if (s[i] != "?") {
				r = i;
				break;
			}
		}
		for (int i = x - 1; i >= 1; i--) {
			if (s[i] != "?") {
				l = i;
				break;
			}
		}
		//cout<<"l=="<<l<<endl;
		//cout<<"r=="<<r<<endl;
		if (l != 0 && r != 0) {
			if (r - x > x - l) {
				for (int i = 0; i < x - l; i++) {
					printf("right of ");
				}
				cout << s[l] << endl;
			}
			else if (r - x == x - l) {
				cout << "middle of " << s[l] << " and " << s[r] << endl;
			}
			else {
				for (int i = 0; i < r - x; i++) {
					printf("left of ");
				}
				cout << s[r] << endl;
			}
		}
		if (!l) {
			for (int i = 0; i < r - x; i++) {
				printf("left of ");
			}
			cout << s[r] << endl;
		}
		if (!r) {
			for (int i = 0; i < x - l; i++) {
				printf("right of ");
			}
			cout << s[l] << endl;
		}
	}
	return 0;
}